package cn.wenlwan.echo;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * creator: maokai
 * on: 2018/2/22
 * description:
 */
public class EchoWellwanServerHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void exceptionCaught (ChannelHandlerContext ctx , Throwable cause) throws Exception {
        // 当出现异常就关闭连接
        cause.printStackTrace();
        ctx.close();
    }

    @Override
    public void channelRead (ChannelHandlerContext ctx , Object msg) throws Exception {
        System.out.println(ctx.channel().remoteAddress()+"->Server :"+ msg.toString());
        ctx.write(msg); // (1)
        ctx.flush(); // (2)
    }
}
